
//泛型类
class comp<T extends Comparable<T>>{
    public T findMax(T[] arr){
        T max = arr[0];
        for(int i = 1; i < arr.length; i++){
            if(arr[i].compareTo(max)>0){
                max=arr[i];
            }
        }
        return max;
    }
}


//泛型方法
class com1{
    public <T extends Comparable<T>> T findMAX1(T[] arr){//也可以用静态
        T max=arr[0];
        for(int i=1; i < arr.length; i++){
            if(arr[i].compareTo(max)>0){
                max=arr[i];
            }
        }
        return max;
    }
}

public class Compar {
    public static void main(String[] args) {
        com1 obj = new com1();
        Integer[] arr = {1,4,9,8,10,3,11};
        System.out.println(obj.findMAX1(arr));
    }


    public static void main1(String[] args) {
        comp<Integer> comp1 = new comp<>();
        Integer[] arr = {1,2,3,4,5,6,7,8,9};
        System.out.println(comp1.findMax(arr));
        System.out.println("===============");
        comp<String> comp2 = new comp<>();
        String[] str={"abcdfg","xabijscb","hsuai"};
        System.out.println(comp2.findMax(str));
    }
}
